package com.github.cosycode.flow.base;

import lombok.NonNull;
import lombok.Setter;

/**
 * <b>Description : </b>
 * <p>
 * <b>created in </b> 2022/12/15
 * </p>
 *
 * @author pengfchen
 * @since 1.0
 **/
public abstract class AbstractAction<R> {

    @Setter
    protected boolean dryRun;

    protected ActionRecord<R> record;

    public abstract R doProcess() throws Exception;

    public void process(@NonNull ActionRecord<R> actionRecord) throws Exception {
        this.record = actionRecord;
        // 实现传入 actionRecord 防止发生异常的时候, 没有办法获取到 actionRecord
        actionRecord.setDryRun(dryRun);
        R result = doProcess();
        actionRecord.setResult(result);
    }
}
